package h.c.z.designPattern.C02_SingletonPattern;

/**
 * 单例模式-懒汉(线程安全，同步方法)（二）[不推荐用]
 * @author jinsicao
 */
public class Singleton_02_02 {

	private static Singleton_02_02 instance = null;
	
	private static int i = 0;
	
	private static int j = 0;
	
	private Singleton_02_02() {
		System.out.println("Singleton_02_02#" + i++);
	}
	
	/**
	 * 线程安全，单线程
	 * @return
	 */
	public static synchronized Singleton_02_02 getInstance() {
		if (instance == null) {
			System.out.println("Singleton_02_02->getInstance#" + j++);
			instance = new Singleton_02_02();
		}
		return instance;
	}
}
